package com.studentmanager.service.Impl;

import com.studentmanager.domain.Activity;
import com.studentmanager.mapper.ActivityMapper;
import com.studentmanager.service.ActivityService;
import com.studentmanager.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ActivityServiceimpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public List<Activity> findbyid(List<Integer> ids) {
        return  activityMapper.getactivityById(ids);
    }
    @Override
    public int addActivity(Activity activity){
        return activityMapper.addactivity(activity);
    }
    @Override
    public  int editActivity(Activity activity){
        return activityMapper.editActivity(activity);
    }
    @Override
    public PageBean<Activity> queryPage(Map<String, Object> paramMap) {
        PageBean<Activity> pageBean = new PageBean<>((Integer) paramMap.get("pageno"),(Integer) paramMap.get("pagesize"));

        Integer startIndex = pageBean.getStartIndex();
        paramMap.put("startIndex",startIndex);
        List<Activity> datas = activityMapper.queryList(paramMap);
        pageBean.setDatas(datas);

        Integer totalsize =activityMapper.queryCount(paramMap);
        pageBean.setTotalsize(totalsize);
        return pageBean;
    }
    @Override
    public int deleteActivity(List<Integer> ids){
        return activityMapper.deleteactivitybyid(ids);
    }
    @Override
    public Integer getStatus(Integer id) {
        return activityMapper.getStatusById(id);
    }
@Override
    // 更新活动状态
    public boolean updateStatus(Integer id, Integer status) {
        int rowsAffected = activityMapper.updateStatusById(id, status);
        return rowsAffected > 0; // 返回是否更新成功
    }
}
